from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-09-07 14:12:58.789426
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Tue, 07, Sep, 2021
Time: 14:13:04
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -46.0227
Nobs: 406.000 HQIC: -46.5593
Log likelihood: 4428.09 FPE: 4.23583e-21
AIC: -46.9108 Det(Omega_mle): 3.40277e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.428925 0.094076 4.559 0.000
L1.Burgenland 0.104704 0.048542 2.157 0.031
L1.Kärnten -0.114364 0.024157 -4.734 0.000
L1.Niederösterreich 0.171171 0.104770 1.634 0.102
L1.Oberösterreich 0.122879 0.102142 1.203 0.229
L1.Salzburg 0.283146 0.050933 5.559 0.000
L1.Steiermark 0.022821 0.067433 0.338 0.735
L1.Tirol 0.108105 0.053334 2.027 0.043
L1.Vorarlberg -0.111897 0.048049 -2.329 0.020
L1.Wien -0.008042 0.092880 -0.087 0.931
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.012411 0.218021 0.057 0.955
L1.Burgenland -0.045869 0.112495 -0.408 0.683
L1.Kärnten 0.037820 0.055984 0.676 0.499
L1.Niederösterreich -0.198572 0.242804 -0.818 0.413
L1.Oberösterreich 0.487410 0.236714 2.059 0.039
L1.Salzburg 0.305159 0.118037 2.585 0.010
L1.Steiermark 0.109958 0.156276 0.704 0.482
L1.Tirol 0.314261 0.123601 2.543 0.011
L1.Vorarlberg -0.000812 0.111353 -0.007 0.994
L1.Wien -0.010132 0.215250 -0.047 0.962
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.254622 0.047682 5.340 0.000
L1.Burgenland 0.089299 0.024603 3.630 0.000
L1.Kärnten -0.002826 0.012244 -0.231 0.817
L1.Niederösterreich 0.206645 0.053103 3.891 0.000
L1.Oberösterreich 0.168197 0.051771 3.249 0.001
L1.Salzburg 0.035439 0.025815 1.373 0.170
L1.Steiermark 0.019729 0.034178 0.577 0.564
L1.Tirol 0.063085 0.027032 2.334 0.020
L1.Vorarlberg 0.059006 0.024354 2.423 0.015
L1.Wien 0.108138 0.047076 2.297 0.022
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.180402 0.046814 3.854 0.000
L1.Burgenland 0.047783 0.024155 1.978 0.048
L1.Kärnten -0.006643 0.012021 -0.553 0.581
L1.Niederösterreich 0.139841 0.052136 2.682 0.007
L1.Oberösterreich 0.316864 0.050828 6.234 0.000
L1.Salzburg 0.099713 0.025345 3.934 0.000
L1.Steiermark 0.131668 0.033556 3.924 0.000
L1.Tirol 0.075825 0.026540 2.857 0.004
L1.Vorarlberg 0.056291 0.023910 2.354 0.019
L1.Wien -0.042079 0.046219 -0.910 0.363
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.208340 0.093092 2.238 0.025
L1.Burgenland -0.056680 0.048034 -1.180 0.238
L1.Kärnten -0.034491 0.023904 -1.443 0.149
L1.Niederösterreich 0.116857 0.103674 1.127 0.260
L1.Oberösterreich 0.167536 0.101074 1.658 0.097
L1.Salzburg 0.257335 0.050400 5.106 0.000
L1.Steiermark 0.080103 0.066728 1.200 0.230
L1.Tirol 0.122683 0.052776 2.325 0.020
L1.Vorarlberg 0.116650 0.047546 2.453 0.014
L1.Wien 0.026050 0.091909 0.283 0.777
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.026618 0.072271 0.368 0.713
L1.Burgenland 0.024922 0.037290 0.668 0.504
L1.Kärnten 0.052007 0.018558 2.802 0.005
L1.Niederösterreich 0.210853 0.080486 2.620 0.009
L1.Oberösterreich 0.336157 0.078467 4.284 0.000
L1.Salzburg 0.044870 0.039127 1.147 0.251
L1.Steiermark -0.004375 0.051803 -0.084 0.933
L1.Tirol 0.113547 0.040972 2.771 0.006
L1.Vorarlberg 0.065619 0.036912 1.778 0.075
L1.Wien 0.130630 0.071352 1.831 0.067
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.187137 0.088248 2.121 0.034
L1.Burgenland 0.020747 0.045534 0.456 0.649
L1.Kärnten -0.058113 0.022660 -2.565 0.010
L1.Niederösterreich -0.115537 0.098279 -1.176 0.240
L1.Oberösterreich 0.190513 0.095814 1.988 0.047
L1.Salzburg 0.027928 0.047777 0.585 0.559
L1.Steiermark 0.299508 0.063255 4.735 0.000
L1.Tirol 0.489674 0.050030 9.788 0.000
L1.Vorarlberg 0.069912 0.045072 1.551 0.121
L1.Wien -0.108803 0.087126 -1.249 0.212
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.155888 0.095979 1.624 0.104
L1.Burgenland -0.006083 0.049523 -0.123 0.902
L1.Kärnten 0.062526 0.024646 2.537 0.011
L1.Niederösterreich 0.198570 0.106889 1.858 0.063
L1.Oberösterreich -0.125319 0.104208 -1.203 0.229
L1.Salzburg 0.236470 0.051963 4.551 0.000
L1.Steiermark 0.155745 0.068797 2.264 0.024
L1.Tirol 0.049735 0.054413 0.914 0.361
L1.Vorarlberg 0.124912 0.049021 2.548 0.011
L1.Wien 0.150356 0.094759 1.587 0.113
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.488448 0.052013 9.391 0.000
L1.Burgenland -0.010654 0.026838 -0.397 0.691
L1.Kärnten -0.010159 0.013356 -0.761 0.447
L1.Niederösterreich 0.208080 0.057926 3.592 0.000
L1.Oberösterreich 0.256177 0.056473 4.536 0.000
L1.Salzburg 0.023795 0.028160 0.845 0.398
L1.Steiermark -0.025351 0.037283 -0.680 0.497
L1.Tirol 0.070257 0.029487 2.383 0.017
L1.Vorarlberg 0.058420 0.026566 2.199 0.028
L1.Wien -0.056042 0.051352 -1.091 0.275
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.020135 0.077791 0.136616 0.134465 0.040862 0.070512 -0.001652 0.175319
Kärnten 0.020135 1.000000 -0.045147 0.126699 0.046860 0.069489 0.456555 -0.094318 0.092108
Niederösterreich 0.077791 -0.045147 1.000000 0.284457 0.084957 0.271684 0.023955 0.145512 0.253674
Oberösterreich 0.136616 0.126699 0.284457 1.000000 0.183180 0.286050 0.157165 0.103782 0.137785
Salzburg 0.134465 0.046860 0.084957 0.183180 1.000000 0.127913 0.059050 0.103900 0.051548
Steiermark 0.040862 0.069489 0.271684 0.286050 0.127913 1.000000 0.130050 0.087564 -0.025517
Tirol 0.070512 0.456555 0.023955 0.157165 0.059050 0.130050 1.000000 0.040511 0.118364
Vorarlberg -0.001652 -0.094318 0.145512 0.103782 0.103900 0.087564 0.040511 1.000000 -0.048368
Wien 0.175319 0.092108 0.253674 0.137785 0.051548 -0.025517 0.118364 -0.048368 1.000000